//
//  WebView.swift
//  MD5
//
//  Created by 郑东喜 on 2016/11/22.
//  Copyright © 2016年 郑东喜. All rights reserved.
//

import UIKit
import WebKit



class WebView: UIViewController,WKUIDelegate,WKNavigationDelegate {

    
    var webView: WKWebView!
    
    override func loadView() {
        
        //获取导航栏高度
//        let navHeight = self.navigationController?.navigationBar.frame.height
//        //获取状态栏高度
//        let statusHeight = UIApplication.shared.statusBarFrame.height

        let webConfiguration = WKWebViewConfiguration()
        webView = WKWebView(frame: .zero, configuration: webConfiguration)
        webView.uiDelegate = self
        self.webView.navigationDelegate = self
        view = webView
    }
    
    func toBack() {
        if self.webView.canGoBack {
            self.webView.goBack()
            
        }
    }
    
    //获取
    func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
        print("\((#file as NSString).lastPathComponent):(\(#line))")
        self.navigationItem.title = self.webView.title
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        
        let myURL = URL(string: "https://www.baidu.com")
        let myRequest = URLRequest(url: myURL!)
        
        let request = NSURLRequest(url: myURL!, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 5.0)
        webView.load(myRequest)
        
        
        
        
        NSURLConnection.sendAsynchronousRequest(request as URLRequest, queue: OperationQueue()) { (res, data, error) in
            
            let request = NSURLRequest(url: myURL!, cachePolicy: .reloadIgnoringCacheData, timeoutInterval: 5.0)
            self.webView.load(request as URLRequest)
        }
        
    }
    


}
